package com.lsk.netdisk.gateway.configure;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;

@Configuration
public class Configure {
	@Bean
	public SimpleClientHttpRequestFactory simpleClientHttpRequestFactory(){
		SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
		String proxyHost = "localhost";
		int proxyPort = 8888;
		if(false){						//True to enable http proxy,close it when Fiddler is not running.
			SocketAddress address = new InetSocketAddress(proxyHost,proxyPort);
			Proxy proxy = new Proxy(Proxy.Type.HTTP,address);
			simpleClientHttpRequestFactory.setProxy(proxy);
		}
		return simpleClientHttpRequestFactory;
	}
	@Bean
	public RestTemplate restTemplate(SimpleClientHttpRequestFactory simpleClientHttpRequestFactory){
		return new RestTemplate(simpleClientHttpRequestFactory);
	}
}
